/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.web.struts;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.*;
import org.apache.struts.util.RequestUtils;

// Referenced classes of package com.web.struts:
//            LinkTag

public class LinkParamTag extends BodyTagSupport
{

    private String id;
    private String value;
    private String name;
    private String property;
    private String scope;


    public LinkParamTag()
    {
        id = null;
        value = null;
        name = null;
        property = null;
        scope = null;
    }

    public void setId(String id)
    {
        this.id = id;
    }

    public String getId()
    {
        return id;
    }

    public void setValue(String value)
    {
        this.value = value;
    }

    public String getValue()
    {
        return value;
    }

    public void setName(String sourceBean)
    {
        name = sourceBean;
    }

    public String getName()
    {
        return name;
    }

    public void setProperty(String sourceProperty)
    {
        property = sourceProperty;
    }

    public String getProperty()
    {
        return property;
    }

    public void setScope(String sourceScope)
    {
        scope = sourceScope;
    }

    public String getScope()
    {
        return scope;
    }

    public int doEndTag()
        throws JspException
    {
        LinkTag myparent = (LinkTag)TagSupport.findAncestorWithClass(this,LinkTag.class);
        if(myparent == null)
            throw new JspException("linkparam tag not nested within link tag");
        BodyContent bodyContent = getBodyContent();
        if(bodyContent != null && !bodyContent.getString().equals(""))
            setValue(bodyContent.getString());
        else
        if(getValue() == null)
            setValue("null");
        myparent.addRequestParameter(getId(), getValue());
        return 0;
    }

    public int doStartTag()
        throws JspException
    {
        if(name != null)
        {
            Object beanValue = RequestUtils.lookup(pageContext, name, property, scope);
            if(beanValue == null)
                return 2;
            setValue(beanValue.toString());
        }
        return 2;
    }

}